package cn.xo68.boot.auth.server.mapper;


import cn.xo68.boot.auth.server.domain.OauthAuthorizationCode;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * OauthAuthorizationCode mybatis mapper
 * @author wuyy(16349023@qq.com)
 * @date 2018年08月26日 21:54:29
 *
 */
public interface OauthAuthorizationCodeMapper {


	@Select("SELECT * FROM oauth_authorization_code WHERE authorization_code = #{authorizationCode}")
    @Results(value = {
    @Result(id = true, column = "authorization_code", property = "authorizationCode"),
        @Result(column = "user_id", property = "userId"),
        @Result(column = "client_id", property = "clientId"),
        @Result(column = "create_time", property = "createTime"),
        @Result(column = "expire_time", property = "expireTime")
    })
    OauthAuthorizationCode get(@Param("authorizationCode") String authorizationCode);
	
	@Select("SELECT * FROM oauth_authorization_code WHERE authorization_code = #{authorizationCode}")
    @Results(value = { 
    @Result(id = true, column = "authorization_code", property = "authorizationCode"),
        @Result(column = "user_id", property = "userId"),
        @Result(column = "client_id", property = "clientId"),
        @Result(column = "create_time", property = "createTime"),
        @Result(column = "expire_time", property = "expireTime")
    })
    OauthAuthorizationCode find(@Param("authorizationCode") String authorizationCode);
	
	@Select("SELECT * FROM oauth_authorization_code")
    @Results(value = { 
    @Result(id = true, column = "authorization_code", property = "authorizationCode"),
        @Result(column = "user_id", property = "userId"),
        @Result(column = "client_id", property = "clientId"),
        @Result(column = "create_time", property = "createTime"),
        @Result(column = "expire_time", property = "expireTime")
    })
    List<OauthAuthorizationCode> list();
	
	@Insert("insert into oauth_authorization_code (authorization_code ,user_id ,client_id ,create_time ,expire_time ) values (#{authorizationCode} , #{userId} , #{clientId} , #{createTime} , #{expireTime}  )")
    @Options(useGeneratedKeys = true, keyProperty = "authorizationCode")
    void insert(OauthAuthorizationCode oauthAuthorizationCode);
	
	@Update("update oauth_authorization_code set  user_id=#{userId}, client_id=#{clientId}, create_time=#{createTime}, expire_time=#{expireTime} where authorization_code = #{authorizationCode}")
    void update(OauthAuthorizationCode oauthAuthorizationCode);

	@Delete("delete FROM oauth_authorization_code WHERE authorization_code = #{authorizationCode}")
	void delete(@Param("authorizationCode") String authorizationCode);
}